package kr.co.casually;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;

public class IntroActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.intro_act);

		Wifi();
		
	}
	
	private void Wifi() {
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		boolean isWifiConn = ni.isConnected();
		NetworkInfo nii = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		boolean isMobileConn = nii.isConnected();

		if (!isMobileConn && !isWifiConn) {
			AlertShow("네트워크를 사용할수 없습니다.\n네트워크 상태를 확인해 주세요!!");
		}else{
			
			Handler mHandler = new Handler();
			mHandler.postDelayed(new Runnable() {
				public void run() {
					Intent intent = new Intent(IntroActivity.this,
							MainActivity.class);
					startActivity(intent);
					finish();
				}
			},2000);
		}	
	}

	private void AlertShow(String msg) {

		AlertDialog.Builder alert_internet_status = new AlertDialog.Builder(
				this);
		alert_internet_status.setTitle("Warning");
		alert_internet_status.setMessage(msg);
		alert_internet_status.setPositiveButton("close",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						finish();
					}
				});
		alert_internet_status.show();
	}
}
